package code;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;

public class Worker{
    private String name;
    private int age;
    private double salary;

    public Worker(){
    }

    public Worker(String name, int age, double salary) {
        this.name = name;
        this.age = age;
        this.salary = salary;
    }

    @Override
    public boolean equals(Object o) {
        Worker worker = (Worker) o;
        return name.equals(worker.name) && age == worker.age && salary == worker.salary;
    }

    @Override
    public int hashCode() {
        return Objects.hash(name);
    }

    public String getName() {
        return name;
    }

    public int getAge() {
        return age;
    }

    public double getSalary() {
        return salary;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public void setSalary(double salary) {
        this.salary = salary;
    }

    public void work(){
        System.out.println(this.name+"正在工作");
    }

    @Override
    public String toString() {
        return name+ " " + age +" " + salary;
    }

    public static void main(String[] args) {
        List<Worker> works = new ArrayList<>();
        works.add(new Worker("凤姐",18,20000.0));
        works.add(new Worker("欧阳锋",60,8000.0));
        works.add(new Worker("刘德华",40,30000.0));
        works.remove(new Worker("刘德华",40,30000.0));
        for (int i = works.size()-1;i>=0;i--){
            System.out.println(works.get(i));
        }

        Iterator<Worker> it = works.iterator();
        while (it.hasNext()){
            it.next().work();
        }
    }
}
